<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "bus_temp_finance".
 *
 * @property string $finance_id
 * @property string $member_id
 * @property string $shop_id
 * @property integer $finance_type
 * @property string $consume_name
 * @property string $sell_price
 * @property string $really_price
 * @property integer $count
 * @property string $total_price
 * @property string $employee_id
 * @property string $reward
 * @property string $session_id
 * @property string $create_time
 */
class BusTempFinance extends \yii\db\ActiveRecord
{
	private $errorMessage;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'bus_temp_finance';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['member_id', 'shop_id', 'finance_type', 'consume_name', 'sell_price', 'really_price', 'count', 'total_price', 'employee_id', 'reward', 'session_id'], 'required'],
            [['member_id', 'shop_id', 'finance_type', 'count', 'employee_id'], 'integer'],
            [['sell_price', 'really_price', 'total_price', 'reward'], 'number'],
            [['create_time'], 'safe'],
            [['consume_name', 'session_id'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'finance_id' => 'Finance ID',
            'member_id' => 'Member ID',
            'shop_id' => 'Shop ID',
            'finance_type' => 'Finance Type',
            'consume_name' => 'Consume Name',
            'sell_price' => 'Sell Price',
            'really_price' => 'Really Price',
            'count' => 'Count',
            'total_price' => 'Total Price',
            'employee_id' => 'Employee ID',
            'reward' => 'Reward',
            'session_id' => 'Session ID',
            'create_time' => 'Create Time',
        ];
    }
    /**
     * 添加收银临时数据
     * @date: 2016-3-2 
     * @author: futao
     * $data['member_id']       not null
     * $data['finance_type']    not null
     * $data['consume_name']
     * $data['sell_price']      not null
     * $data['really_price']    not null
     * $data['count']           not null
     * $data['total_price']     not null
     * $data['employee_id']
     * $data['reward']
     * $data['session_id']      not null
     */
    public function add($shopId,$data)
    {
    	if($shopId=='' || $data['session_id']=='' || $data['count']=='' || $data['sell_price']=='' || $data['really_price']=='' || $data['total_price']=='' || $data['finance_type']==''){
    		$this->setError('参数不全！');
    		return false;
    	}
    	$this->setAttributes($data);
    	$this->shop_id = $shopId;
    	$this->create_time = date('Y-m-d H:i:s',time());
    	return $this->insert(false);
    	
    }
    private function setError($errormessage)
    {
    	$this->errorMessage=$errormessage;
    }
    public function getErrormessage()
    {
    	return $this->errorMessage;
    }
    
}
